/*#define GLEW_STATIC
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "graphics.h"
#include "settings.h"
#include "keyboard.h"
#include "log.h"
#include "texture.h"
#include <cmath> // ei tarvii
#include <signal.h> //sigterm
#include "player.h"*/

//#include "constants.h"
//#include <windows.h>
#include "game.h"

//GLfloat cameraX = 0.f, cameraY = 0.f;
//cTexture gCheckerBoardTexture;

// Shader sources
/*const GLchar* vertexSource =
    "#version 150 core\n"
    "in vec2 position;"
    "in vec3 color;"
    "out vec3 Color;"
    "void main() {"
    "   Color = color;"
    "   gl_Position = vec4(position, 0.0, 1.0);"
    "}";
const GLchar* fragmentSource =
    "#version 150 core\n"
    "in vec3 Color;"
    "out vec4 outColor;"
    "void main() {"
    "   outColor = vec4(Color, 1.0);"
    "}";*/

/*bool loadMedia()
{
    //Checkerboard pixels
	const int CHECKERBOARD_WIDTH = 128;
	const int CHECKERBOARD_HEIGHT = 128;
	const int CHECKERBOARD_PIXEL_COUNT = CHECKERBOARD_WIDTH * CHECKERBOARD_HEIGHT;
    GLuint checkerBoard[ CHECKERBOARD_PIXEL_COUNT ];

    //Go through pixels
    for( int i = 0; i < CHECKERBOARD_PIXEL_COUNT; ++i )
    {
		//Get the individual color components
        GLubyte* colors = (GLubyte*)&checkerBoard[ i ];

        //If the 5th bit of the x and y offsets of the pixel do not match
        if( i / 128 & 16 ^ i % 128 & 16 )
        {
            //Set pixel to white
            colors[ 0 ] = 0xFF;
            colors[ 1 ] = 0xFF;
            colors[ 2 ] = 0xFF;
            colors[ 3 ] = 0xFF;
        }
        else
        {
            //Set pixel to red
            colors[ 0 ] = 0xFF;
            colors[ 1 ] = 0x00;
            colors[ 2 ] = 0x00;
            colors[ 3 ] = 0xFF;
        }
    }

    //Load texture
    if( !gCheckerBoardTexture.loadTextureFromPixels32( checkerBoard, CHECKERBOARD_WIDTH, CHECKERBOARD_HEIGHT ) )
    {
		//printf( "Unable to load checkerboard texture!\n" );
        return false;
    }

    return true;
}*/

int main(int argc, char *argv[])
{
    if (!cGame::instance().init())
        return 1;

    cGame::instance().loop();
    cGame::instance().shutdown();

    return 0;

    /*void (*prev_handler)(int);
    prev_handler = signal (SIGTERM, clean);*/

   // Create Vertex Array Object
    /*GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    // Create a Vertex Buffer Object and copy the vertex data to it
    GLuint vbo;
    glGenBuffers(1, &vbo);

    float vertices[] = {
         0.0f,  0.5f, 1.0f, 0.0f, 0.0f, // Vertex 1: Red
         0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // Vertex 2: Green
        -0.5f, -0.5f, 0.0f, 0.0f, 1.0f  // Vertex 3: Blue
    };

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    // Create and compile the vertex shader
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vertexSource, NULL);
    glCompileShader(vertexShader);

    // Create and compile the fragment shader
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
    glCompileShader(fragmentShader);

    // Link the vertex and fragment shader into a shader program
    GLuint shaderProgram = glCreateProgram();
    glAttachShader(shaderProgram, vertexShader);
    glAttachShader(shaderProgram, fragmentShader);
    glBindFragDataLocation(shaderProgram, 0, "outColor");
    glLinkProgram(shaderProgram);
    glUseProgram(shaderProgram);

GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE,
                       5*sizeof(float), 0);

GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
glEnableVertexAttribArray(colAttrib);
glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE,
                       5*sizeof(float), (void*)(2*sizeof(float)));*/

/*
            if (windowEvent.type == SDL_QUIT)
                return 0;

            if (windowEvent.type == SDL_KEYUP &&
                windowEvent.key.keysym.sym == SDLK_F9) graphics.toggleFullscreen();

            if (windowEvent.type == SDL_KEYUP &&
                windowEvent.key.keysym.sym == SDLK_F10) graphics.setVsync(false);
        }
*/

        // Set the color of the triangle
        //GLfloat time = (GLfloat)SDL_GetTicks() / (GLfloat)1000;
        //glUniform3f(uniColor, (sin(time * 4.0f) + 1.0f) / 2.0f, (sin(time * 4.0f)), (sin(time * 4.0f) + 0.5f));

/*
        //Clear color buffer
        glClear(GL_COLOR_BUFFER_BIT);

        //Pop default matrix onto current matrix
        glMatrixMode( GL_MODELVIEW );
        glPopMatrix();

        //Save default matrix again
        glPushMatrix();

        //Move to center of the screen
        //glTranslatef( 640 / 2.f, 480 / 2.f, 0.f );

        //Render checkerboard texture
        gCheckerBoardTexture.render( 500,300 );

*/
    /*glDeleteProgram(shaderProgram);
    glDeleteShader(fragmentShader);
    glDeleteShader(vertexShader);

    glDeleteBuffers(1, &vbo);

    glDeleteVertexArrays(1, &vao);*/
}
